package com.qf.lanzhou.blog.api.controller;

import com.alibaba.fastjson.JSON;
import com.qf.lanzhou.blog.api.dao.FeedbackDao;
import com.qf.lanzhou.blog.api.dao.Impl.FeedbackDaolmpl;
import com.qf.lanzhou.blog.api.pojo.entity.FeedbackEntity;
import com.qf.lanzhou.blog.api.pojo.vo.BaseRespVO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author jack
 * 用户反馈查询服务器
 */
@WebServlet("/feedbackSelect.do")
public class FeedbackSelectServlet extends HttpServlet {
    private FeedbackDao feedbackDao = new FeedbackDaolmpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //连接服务器
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
        System.out.println("用户反馈查询服务器连接成功，doGet");
        //查询结果
        List<FeedbackEntity> list = feedbackDao.selectAll();
        for (int i = 0; i < list.size(); i++) {
            list.get(i).setStandarTime(list.get(i).getFbCreatedtime());
        }
        System.out.println(list);
        //结果存到标准
        BaseRespVO<Object> baseRespVO = new BaseRespVO<>();
        baseRespVO.setData(list);
        //标准转换成json，返回给前端
        String json = JSON.toJSONString(baseRespVO);
        System.out.println(json);
        resp.getWriter().write(json);
    }
}
